<template>
  <div>
    <div style="background-color: pink">
      <div style="text-align: center">
        <slot name="title"></slot>
      </div>
      <table v-if="list.length > 1">
        <tr>
          <th v-for="(item, index) in allTitle" :key="index">{{ item }}</th>
        </tr>
        <!-- 作用域插槽传出每一项-->
        <tr v-for="(item, index) in list" :key="index">
          <slot :item="item"> </slot>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
export default {
  props: ['list'],
  name: 'childTwo',
  components: {},
  data() {
    return {}
  },

  computed: {
    // 计算出头部的标题
    allTitle() {
      let result = []
      if (this.list && this.list.length > 0) {
        result = Object.keys(this.list[0])
      }
      return result
    }
  },
  methods: {},
  activated: {},
  deactivated: {}
}
</script>
<style lang="less" scoped>
table {
  border: 1px solid lightblue;
  overflow-x: scroll;
  td,
  th {
    text-align: center;
    padding: 4px;
    border: 1px dashed orchid;
  }
}
</style>
